<!-- 今日标准服务人工智能使用次数 -->
<template>
  <div class="wrap">
    <span class="title"> 企智库分类统计<!-- <span style="margin-left:10px">（{{this.total}}次）</span> --></span>
    <el-row :gutter="20">
      <el-col :xs="24" :sm="24" :lg="24">
        <piechart :title="'访问用户统计分析'" id="chart35" :chartData="pieData" />
      </el-col>
    </el-row>

  </div>
</template>
<script>
import piechart from "./piechart.vue";
import { connrequest } from "@/api/firstPage";
export default {
  components: { piechart },
  data() {
    return {
      dataList: [],
      pieData: [],
      listTime: [{ 'StartTime': '', 'EndTime': '' }],
      total: 0
    };
  },
  //生命周期 - 创建完成（访问当前this实例）
  created() {
    this.getData();
  },
  //生命周期 - 挂载完成（访问DOM元素）
  mounted() { },
  methods: {
    getTimeList(i) {
      // 获取当前日期
      var today = new Date();
      this.listTime[0].StartTime = formatDate(today, 0, true)
      this.listTime[0].EndTime = formatDate(today, 0, false)
      function formatDate(date, daysToAdd, isStart) {
        var newDate = new Date(date);
        newDate.setDate(date.getDate() - daysToAdd);
        var year = newDate.getFullYear();
        var month = String(newDate.getMonth() + 1).padStart(2, '0');
        var day = String(newDate.getDate()).padStart(2, '0');
        var hours = isStart ? '00' : '23';
        var minutes = isStart ? '00' : '59';
        var seconds = isStart ? '00' : '59';
        return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
      }
    },
    async getData() {
      let arr = []

      this.getTimeList()
      // const data = {
      //   Filter: {
      //     StartTime: this.listTime[0].StartTime,
      //     EndTime: this.listTime[0].EndTime,
      //     TransDate: '',
      //     Name:  '',
      //     Descp:'',
      //     SumCount: 10,
      //     MsgSubType:'3.5'
      //   }
      // }
      const res = await connrequest('GetDictKnowledgeClass');
      if (res.Data) {
        // 过滤掉 Count = 0 的项
        const filtered = res.Data.filter(item => item.Count > 0);

        // 按 Count 倒序排序，取前 10
        const top10 = filtered
          .sort((a, b) => b.Count - a.Count)
          .slice(0, 10);

        const arr = [];
        this.total = 0; // 重置 total

        top10.forEach(item => {
          arr.push({ name: item.Class, value: item.Count });
          this.total += item.Count;
        });

        this.pieData = arr;
        this.dataList = top10;
      } else {
        const dom = document.getElementById('chart35');
        dom.innerHTML = '<div class="el-table__empty-block"><span class="el-table__empty-text">暂无数据</span></div>';
        dom.removeAttribute('_echarts_instance_');
      }
    }
  }
};
</script>
<style scoped lang='scss'>
.wrap {
  height: calc(50vh - 50px) !important;
  overflow: hidden;
}

.night {
  .wrap {
    .el-col-lg-24 {
      background: #303445;
    }

    ::v-deep .el-table__empty-block {
      background-color: #303445 !important;
    }
  }
}
</style>
